<template>
	<view class="meetingpay">
		<view class="meetingprompt">{{data2.prompt}}</view>
		<view class="addname">
			<view class="addshow">参加会议名称</view>
			<view class="addtitle">{{data2.title}}</view>
		</view>
		<view class="addname">
			<view class="addshow">参加人数</view>
			<view class="addtitle">{{data2.addnum}}</view>
		</view>
		<view class="addname">
			<view class="addshow">单价</view>
			<view class="addtitle">￥{{data2.money}}</view>
		</view>
		<view class="addname">
			<view class="addshow">总金额</view>
			<view :class="['addtitle', data2.vipnub !=1?'allmon':'']" >￥{{data2.money}}</view>
			<view class="addtitle" v-if="data2.vipnub !=1">卓越创新联盟成员价格￥{{data2.allmoney}}</view>
		</view>
		<view class="addname">
			<view class="addshow">发票抬头</view>
			<view class="addtitle">{{data1.invoiceTitle}}</view>
		</view>
		<view class="addname">
			<view class="addshow">纳税人识别号</view>
			<view class="addtitle">{{data1.taxpayerCode}}</view>
		</view>
		<view class="changeinfo" @click="changeinfofn">点击修改报名信息</view>
		<view class="paybox">
			<view class="loadpay als" @click="loadpayfn">线下支付</view>
			<view class="wxpay als" @click="wxpay">微信支付</view>
		</view>
	</view>
</template>

<script>
	import {common} from '@/common/publish.js';
	export default {
		data() {
			return {
				even:{},
				lvarr:['A','AA','AAA'],
				data1:{},
				data2:{}
			};
		},
		onLoad(event) {
			//console.log(event.signupid) //159
			//console.log(event.meetingid) //76  
			this.even = event;
			//this.even.money = parseInt(this.even.allmoney/this.even.vipnub)
			this.getval();
		},
		methods: {
			
			changeinfofn(){
				var that = this;
				uni.redirectTo({
					url: '/pages/meetingchange/meetingchange?signupid='+that.even.signupid+'&meetingid='+that.even.meetingid 
				});
			},
			wxpay(){
				var that = this;
				var paymoney = that.data2.allmoney*100;
				//console.log(paymoney)
				uni.getProvider({
					service: 'payment',
					success: function (res) {
						if (~res.provider.indexOf('wxpay')) {
							uni.request({
								url: common.localurl+'/guoyu/app/pay.json' , 
								data: {
									signUpId: that.even.signupid,
									money: paymoney
								},
								success: (res) => {
									var varpay = {//参数顺序必须正确
										retcode: 0,//5+必备参数
										retmsg: "ok",//5+必备参数
										appid: res.data.appid,
										noncestr: res.data.noncestr,
										package: "Sign=WXPay",
										partnerid: res.data.partnerid,
										prepayid: res.data.prepayid,
										timestamp: parseInt(res.data.timestamp),
										sign: res.data.sign,
									}
									console.log(JSON.stringify(res.data))
									uni.requestPayment({
										provider: 'wxpay',
										orderInfo: varpay, 
										success: function (res) {
											uni.showToast({
												title: '微信支付成功',
												duration: 2000,
												success:function(){
													
													uni.request({
														url: common.localurl+'/guoyu/wx/updateStatus.json' , 
														data: {
															signUpId: that.even.signupid
														},
														success: (res) => {
															uni.redirectTo({
																url: '/pages/meetingorder/meetingorder'
															});
														}
													});	
												},
											})
										},
										fail: function (err) {
											console.log('fail:' + JSON.stringify(err));
											uni.showToast({
												title: '微信支付失败',
												duration: 2000,
												icon:'none'
											})
										}
									});
								}
							});
							
						}
					}
				});
			},
			loadpayfn(){
				var that = this;
				uni.navigateTo({
					url: '/pages/meetingloadpay/meetingloadpay?meetingid='+ that.even.meetingid 
				});
			},
			getval(){
				var that = this;
				uni.request({
					url: common.localurl+'/api/pc/toEdit.json' , 
					data: {
						signUpId: that.even.signupid
					},
					success: (res) => {
						this.data1 = res.data
					}
				});
				uni.request({
					url: common.localurl+'/api/meeting/detail.json' , 
					data: {
						meetingId: that.even.meetingid
					},
					success: (res) => {
						this.data2 = res.data
						this.getlv(this.data2.signUps[0].invoiceTitle)
					}
				});
			},
			getlv(val){
				var that = this;
				uni.request({
					url: common.localurl+'/api/lv/queryLv.json' ,
					data: {
						title: val
					},
					success: (res) => {
						//获取级别
						var lv = ''
						var vipnub = 1;
						if(res.data.level){
							lv = 'type'+that.lvarr[res.data.level-1]
							vipnub = datas[lv]
						}
						that.data2.vipnub = vipnub;
						that.getnub(vipnub)
					}
				});
			},
			//获取人数
			getnub(vipnub){
				var that = this;
				uni.request({
					url: common.localurl+'/api/pc/attCount.json' ,
					data: {
						signUpId: that.even.signupid
					},
					success: (res) => {
						//人数
						that.data2.addnum = res.data;
						var allmoney= that.data2.money*that.data2.addnum*vipnub;
						that.data2.allmoney=parseInt(allmoney*100)/100;
						that.data2.money  = parseInt(that.data2.allmoney/vipnub);
						this.$forceUpdate();
					}
				});
			}
		},
	}
</script>

<style lang="scss">
	@import "@/common/publish.scss";
	page {
		background-color: $bgcolor;
	}
	.meetingpay{
		padding:20upx 24upx;
	}
	.meetingprompt{
		font-size:30upx;
		color:$titlecolor;
		line-height:50upx;
		text-indent: 2em;
		margin-bottom:10upx;
	}
	.addname{
		margin-top:20upx;
	}
	.addshow{
		font-size:30upx;
		color:$timecolor;
		line-height:60upx;
	}
	.addtitle{
		font-size:30upx;
		color:$titlecolor;
		line-height:60upx;
		padding:16upx 0;
		border-bottom:1px solid #ccc;
	}
	.changeinfo{
		line-height:100upx;
		color:red;
		text-align: center;
		text-decoration:underline;
		font-size:28upx;
		margin-top:20upx;
	}
	.paybox{
		display: flex;
		flex-direction:row;
		flex-wrap:nowrap ;
		justify-content:space-around;
		align-items:flex-start;
	}
	.als{
		width:240upx;
		height:80upx;
		font-size:32upx;
		color:#fff;
		line-height:80upx;
		text-align:center;
		border-radius:8upx;
		background-color: $fontblue;
		margin-top:20upx;
	}
	.wxpay{
		background-color: #dd6264;
	}
	.allmon{
		color:$timecolor;
		text-decoration: line-through;
	}
</style>
